import { resources } from "cc"
import { JsonAsset } from "cc"
import { RoleCfg } from "./RoleCfg"

export class Cfg {
    static Role: RoleCfg = new RoleCfg()

    static loadAllCfg(): Promise<void> {
        return new Promise((resolve, reject) => {
            resources.loadDir("config/client", JsonAsset, (err: Error, assets: JsonAsset[]) => {
                if (err) {
                    console.error(err)
                    reject();
                    return;
                }
				assets.forEach(asset => {
                    this[asset.name].data = asset.json
                })
                resolve();
            })
        });
    }

    static loadSingleCfg(name: string): Promise<void> {
        return new Promise((resolve, reject) => {
            resources.load("config/client/"+name, JsonAsset, (err: Error, asset: JsonAsset) => {
                if (err) {
                    console.error(err)
                    reject();
                    return;
                }
                this[asset.name].data = asset.json
                resolve()
            })
        })
    }
}